<template>
	<page-meta :root-font-size="`${fontSize}px`"></page-meta>
	<view class="activity-wrapper">
		<view style="display: flex;justify-content: center;padding: 40rpx 0;width: 80%;margin:auto;font-size: 32rpx;">
			<view @click="onStatusChange(2)" :class="{'btn-status':true, active:status==2}" type="default">未开始</view>
			<view @click="onStatusChange(3)" :class="{'btn-status':true, active:status==3}" type="default">进行中</view>
			<view @click="onStatusChange(4)" :class="{'btn-status':true, active:status==4}" type="default">已结束</view>
		</view>
		<view class="activity-list">
			<view v-for="(item,index) in list" :key="index" class="list-item" @click="activityClick(item.id)">
				<view class="title-bar">
					<view class="title">
						{{item.activityName}}
					</view>
					<view :class="{status:true, voted:item.isVoted}">
						{{item.isVoted?'已参与':'未参与'}}
					</view>
				</view>
				<view class="content">
					{{item.activityContent}}
				</view>
				<view class="footer">
					<view class="">
						<view class="">
							开始时间：{{$funcs.toLocalTime(item.startTime)}}
						</view>
						<view class="">
							结束时间：{{$funcs.toLocalTime(item.endTime)}}
						</view>

					</view>
					<view class="voters">
						{{item.voter}}人已参与
					</view>
				</view>
			</view>
			<uni-load-more :status="more" v-if="list.length>0"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		computed: {
			...mapState(['fontSize'])
		},
		data() {
			return {
				status: 3, //3:进行中，2：即将开始，4：已结束
				current: 1,
				pages: 1,
				list: [],
				more: 'more',
				rawlist: [{
						id: 1,
						activityName: "星桥街道最美志愿者投票撒打发斯蒂芬撒旦法 ",
						activityType: 1,
						activityContent: "感谢参与本次投票活动，选出最佳的社区党支部干部！！我们社区真诚的希望您可以参与以下调研内容，为我们提供宝贵的意见。",
						voter: 12234,
						isVoted: false,
						status: 4,
						startTime: '2021-07-14 18:00:00',
						endTime: '2021-08-14 18:00:00',
					},
					{
						id: 2,
						activityName: "星桥街道最美环卫工人投票",
						activityType: 1,
						activityContent: "感谢参与本次投票活动，选出最佳的社区党支部干部！！我们社区真诚的希望您可以参与以下调研内容，为我们提供宝贵的意见。",
						voter: 234,
						isVoted: true,
						status: 3,
						startTime: '2021-07-14 18:00:00',
						endTime: '2021-08-14 18:00:00',
					},
					{
						id: 3,
						activityName: "星桥街道最美城管投票",
						activityType: 1,
						activityContent: "感谢参与本次投票活动，选出最佳的社区党支部干部！！我们社区真诚的希望您可以参与以下调研内容，为我们提供宝贵的意见。",
						voter: 1234,
						isVoted: false,
						status: 2,
						startTime: '2021-07-14 18:00:00',
						endTime: '2021-08-14 18:00:00',
					}
				]
			}
		},
		onShow() {
			this.getVoteList(this.status)
		},
		mounted() {
			this.getVoteList(this.status)
		},
		onPullDownRefresh() {
			this.getVoteList(this.status)
		},
		onReachBottom() {
			this.getVoteList(this.status, true)
			this.more = 'loading'
		},
		methods: {
			getVoteList(status, isMore) {		
				
				//加一页
				if (isMore && this.pages > this.current) {
					this.current++
				}

				uni.showLoading({
					title: '加载中'
				});

				this.$http.post('vx/activity/list', {
					projectId: uni.getStorageSync('projId'),
					activityType: 1,
					status: status,
					pagination: {
						"pageSize": 10,
						"current": this.current
					},
					sorter: {
						"field": "id",
						order: 0
					}
				}).then(
					res => {
						uni.stopPullDownRefresh();
						if (res.code == 10000) {
							let list = res.data.list || []
							this.pages = res.data.total / 10 + 1

							console.log(isMore)
							if (isMore) {
								if (this.pages > this.current) {
									this.list = this.list.concat(list)
								} else {
									this.more = 'nomore'
								}

							} else {
								this.list = list
							}
						}
					}
				)

			},
			onStatusChange(status) {
				this.more = 'nomore'
				this.current = 1
				this.status = status
				this.getVoteList(this.status)

			},
			activityClick(id) {
				uni.navigateTo({
					url: '../voteInfo/voteInfo?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.activity-wrapper {
		font-size: 32rpx;

		.btn-status {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 6rpx;
			border: 1rpx solid $theme-color;
			color: $theme-color;

		}

		.btn-status:first-child {
			border-radius: 12rpx 0 0 12rpx;
			border-right: none;
		}

		.btn-status:last-child {
			border-left: none;
			border-radius: 0 12rpx 12rpx 0;
		}

		.btn-status.active {
			background-color: $theme-color;
			color: #FFFFFF;
		}

		.activity-list {
			padding: 0 20rpx;

			.list-item {
				padding: 40rpx 30rpx;
				border-bottom: 1rpx solid #d5d5d5;

				.title-bar {
					position: relative;
					display: flex;
					justify-content: space-between;

					.title {
						flex: 1;
					}

					.title::before {
						content: "";
						width: 10rpx;
						height: 32rpx;
						display: inline-block;

						background-color: $theme-color;
						transform: translate(-16rpx, 4rpx);

					}

					.status {
						color: grey;
						font-size: .8em;
						width: 100rpx;
						text-align: right;
					}

					.voted {
						color: #55aa00;
					}
				}

				.content {
					text-indent: 2em;
					font-size: .8em;
					line-height: 1.5;
					color: #a2a2a2;
					margin: 30rpx 0;
				}

				.footer {
					display: flex;
					justify-content: space-between;
					font-size: 0.8em;
					color: #717171;

					.voters {
						font-size: 1em;
						color: $theme-color;
					}
				}
			}
		}


	}
</style>
